package com.example.uberorganizer;


import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


//Okno dodawania wydarzenia
public class EventDialog extends DialogFragment {
	public static long startTime;
	public static long endTime;
	public static TextView t1;
	public static TextView t2;
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
	    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
	    // Get the layout inflater
	    LayoutInflater inflater = getActivity().getLayoutInflater();
	    // Inflate and set the layout for the dialog
	    // Pass null as the parent view because its going in the dialog layout
	    View v = inflater.inflate(R.layout.add_event_dialog, null);
		t1 = (TextView)v.findViewById(R.id.starttimetext);
		t2 = (TextView)v.findViewById(R.id.endtimetext);
	    builder.setView(v)
	    // Add action buttons
	           .setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() {
	        	   //Na przycisku OK dodajemy wydarzenie na Cancel wychodzimy z okna
	               @Override
	               public void onClick(DialogInterface dialog, int id) 
	               {
	            	   
	            	   
	            	   EditText title=(EditText)EventDialog.this.getDialog().findViewById(R.id.eventtitle);
	            	   EditText description=(EditText)EventDialog.this.getDialog().findViewById(R.id.eventdescription);
	            	   
	            	   //dodanie wydarzenia
	            	   Utility.putCalendarEvent(getActivity(), title.getText().toString(), description.getText().toString(), startTime, endTime);
	            	   try {
	            	   ((UserInterfaceOne)getActivity()).Reload();
	           			} catch (ClassCastException cce) {
	           				((UserInterfaceFour)getActivity()).Reload();
	           			}
	               }
	           })
	           .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
	               public void onClick(DialogInterface dialog, int id) {
	            	   EventDialog.this.getDialog().cancel();
	               }
	           });      
	    return builder.create();
	}
	

}
